
// https://leetcode.cn/problems/minimum-size-subarray-sum/
public class MinSubArrayLen {
    class Solution {
        public int minSubArrayLen(int target, int[] nums) {
            int [] prefix = new int[nums.length + 1];
            for(int i = 0 ; i < nums.length ; i ++ ){
                prefix[i + 1] = prefix[i] + nums[i];
            }
            int res = 0x3f3f3f3f;
            int left = 0;
            for(int right = 0 ; right < prefix.length ; right ++){
                while(left <= right){
                    if(prefix[right] - prefix[left] >= target){
                        res = Math.min(res,right-left);
                        left ++;
                    }else{
                        break;
                    }
                }
            }
            return res == 0x3f3f3f3f ? 0 : res;


        }
    }
}
